

var numAjax=0;

$(document).ajaxSuccess(function(evt, request, settings){  
  numAjax++;
  if (numAjax>=2) {
    $('.loading').hide()
  }
}); 
var vm = new Vue({
  el:'#app',
  data: {
    res:[],
    imgUrl:imgUrl
  },
  methods: {
 
      },
});

var searchForm = new Vue({
  el:'#searchForm',
  data: {
    shopList:[]
  }, 
  methods: {
 
    },
});

$.get(defaultUrl+"/controller/getShopList?marketId="+marketId,function(res){
  searchForm.shopList = res.result;
},'json');


function getShopList(marketId){
  $.get(defaultUrl+"/controller/getShopList?marketId="+marketId,function(res){
    searchForm.shopList = res.result;
  },'json');
  $('select[name=shopId]').val('');
}


var pageIndexNow = 1;

$('#serchFirstDetectBtn').click(function(){
  $('.loading').show();
  initSearchList(1,$('#searchForm').serialize());
})

function initSearchList(pageIndex,params){
  $('.loading').show();
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/car/getCarFirstDetectList",  // yii 控制器/方法
    cache: false,      
    data: params + '&pageIndex='+pageIndex+'&pageSize=10',  //传送的数据
    error:function(){
       alert("数据传输错误");
    },success: function (data) {
      // console.log(data);
      if (data.code != 1) {
        $('.loading').hide();
        return false
      }
      vm.res = data.result;
      $('.loading').hide();

    }
  });
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/getCarNum",  // yii 控制器/方法
    cache: false,      
    data: params,  //传送的数据
    error:function(){
       console.log("数据传输错误");
       $('.loading').hide();
    },success: function (data) {
      // console.log(data);
      if (data.code != 1) {
        console.log(data.msg);
        $('.loading').hide();
        return false;
      }
      $('.loading').hide();
      var pageTotal = data.result.total;
      var pageNumTotal = Math.ceil(pageTotal/10);
      $("#page").paging({
        pageNo:pageIndex,
        totalPage: pageNumTotal,
        totalSize: pageTotal,
        callback: function(num) {
          pageIndexNow = num;
          initSearchList(num,params)
        }
      });
    }
  });
}
initSearchList(1,$('#searchForm').serialize());




//所有操作


//车辆日志
var carLog = new Vue({
  el:'#carLogBox',
  data: {
    logList:[],
    log:{
    	user:{}
    }
  }, 

});

//查看车辆操作日志
function showCarLogDetect(id){
	console.log(id)
	var detectState = document.getElementById(id);
	detectState = detectState.dataset.detectstate;
	console.log(detectState)
	detectState = detectState > 520?520:detectState;
	console.log(detectState)
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/carLog/getCarLogList",  // yii 控制器/方法
    cache: false,      
    data: {'carId': id,'carStateKey':'carDetectState','carStateValue':detectState},  //传送的数据
    error:function(){
       alert("数据传输错误");
    },success: function (data) {
      if (data.code != 1) {
        layer.msg(data.msg, {icon: 1});
        return false;
      }
      carLog.logList = data.result;
      carLog.log=carLog.logList[0];
      setTimeout(function(){
        var carLogHtml = $('#carLogBox').html();
        layer.open({
          type: 1,
          title: '操作日志',
          closeBtn: 1,
          shadeClose: true,
          area: ['400px', '200px'],
          content: carLogHtml,
        });
      },100)
    }
  });
}
